﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.CloudSaver.Web.Infrastructure;

namespace Microsoft.CloudSaver.Web.Components
{
    public partial class Settings : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack){
                txtCompany.Text = CloudUtils.GetValue("CompanyName");
                txtUrl.Text = CloudUtils.GetValue("CompanyUrl");
            }
        }
               
        protected void logoValidator_ServerValidate(object source, ServerValidateEventArgs args)
        {
            
        }

        protected void cmdSave_Click(object sender, EventArgs e)
        {
            if (upload.HasFile) logoValidator.IsValid = CloudUtils.CheckAndUploadCompanyLogo(upload.PostedFile, upload.FileBytes);            
            if (Page.IsValid)
            {
                CloudUtils.SetValue("CompanyName", txtCompany.Text);
                CloudUtils.SetValue("CompanyUrl", txtUrl.Text);
                lblOk.Visible = true;
            }
        }

        protected void imgFromBlob_Load(object sender, EventArgs e)
        {
            imgFromBlob.ImageUrl = CloudUtils.GetCompanyLogoUrl();
        }

        
    }
}